/*
 * A class that acts as a bank account for a banking system.  
 * 
 */

import java.lang.Math;
import java.lang.Exception;
public class BankAccount {

	private double balance;
	private double interestRate;
	private String ownerName;
	private String accountNickName;
	private int accountType; //1 = checking, 2 = savings
	private int ownerId;
	private int accountNum;

	//Main constructor for the bank account class
	public BankAccount(int accountNumber, int ownerIDNum,  int type, String ownerFullName, String nickName, double balance, double interestRate){
		balance=0.0;
		interestRate=0.0;
		accountType=type;
		accountNum=accountNumber;
		ownerId=ownerIDNum;
		ownerName=ownerFullName;
		accountNickName=nickName;
	}
	
	//Copy constructor for the bank account class
	public BankAccount(BankAccount account){
		balance=account.balance;
		interestRate=account.interestRate;
		accountNum=account.accountNum;
		ownerId=account.ownerId;
		ownerName=account.ownerName;
		accountNickName=account.accountNickName;
	}
	
	
	//Used to get the balance of this bank account
	public double getBalance() {
		return balance;
	}
	
	//Used to get the interest rate of this bank account
	public double getInterestRate() {
		return interestRate;
	}
	
	public boolean setInterestRate(double IR){
		interestRate=IR;
		return true;
	}
	
	//Used to get the account number of this bank account
	public int getAccountNum() {
		return accountNum;
	}
	
	//Used to get the account type of this bank account
	public int getAccountType() {
		return accountType;
	}
	//Used to get the ownerId of this bank account
	public int getOwnerID() {
		return ownerId;
	}
	
	//Used to get the ownerId of this bank account
	public String getOwnerName() {
		return ownerName;
	}
	
	//Used to get the ownerId of this bank account
	public String getNickName() {
		return accountNickName;
	}
	
	//Deposits money into the account
	public void deposit(double amount){
		
		//add the money into the account
		balance=Math.floor(balance*100+amount*100)/100;
		
		//update it in the database
		AbsDatabase.updateAccount(this,accountNum);
	}
	
	public void withdraw(double amount) throws Exception{
		
		//check available funds
		if(amount>balance){
			throw new Exception("Insufficient Funds\n");
		}
		
		//remove money from the account
		balance=Math.floor(balance*100-amount*100)/100;
		
		//update it in the database
		AbsDatabase.updateAccount(this,accountNum);
	}
	
	//adds interest for this payment period to the account
	public void addInterest(){
		balance=Math.floor(balance*(1.0+(interestRate/100.0)));
	}

	
}
